package cn.zwk.handler;

import cn.zwk.entity.AbstractItem;
import cn.zwk.entity.DataRow;
import cn.zwk.entity.MetricList;
import cn.zwk.entity.Snapshoot;
import cn.zwk.resolver.MetricListText;
import lombok.Data;

@Data
public abstract class MetricHandler {
    protected String type;

    public abstract MetricList buildMetric(MetricListText text);

    public abstract void next(AbstractItem item);

    public DataRow parseRow(String row) {
        String[] parts = row.trim().split("\\s+");
        if (parts.length < 2) return null;
        
        DataRow dataRow = new DataRow();
        String metricPart = parts[0];
        dataRow.setKey(metricPart);
        try {
            double value = Double.parseDouble(parts[1]);
            dataRow.setVal(value);
        } catch (NumberFormatException e) {
            return null;
        }
        
        return dataRow;
    }
}
